//
//  SuperViewController.m
//  test
//
//  Created by apple on 16/3/25.
//  Copyright © 2016年 ibendi. All rights reserved.
//


#import "SuperViewController.h"
#import "LogInViewController.h"

@interface SuperViewController ()
{
    IBDEmptyView *_emptyView;
}
@end

@implementation SuperViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view_startY=[self.navigationController.navigationBar isTranslucent]?64:0.0;
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self addNoResultView];
    

}
-(void)hideNavigationBarBackItem
{
    [self.navigationItem setHidesBackButton:YES];
}
-(void)showNavigationBarBackItem
{
    [self.navigationItem setHidesBackButton:NO];
}

-(void)setNavigationTitle:(NSString *)title
{
    UILabel *titleLabel=[[UILabel alloc] init];
    [titleLabel setBackgroundColor:[UIColor clearColor]];
    [titleLabel setTextAlignment:NSTextAlignmentCenter];
    [titleLabel setTextColor:[UIColor whiteColor]];
    [titleLabel setFont:[UIFont boldSystemFontOfSize:18]];
    [titleLabel setText:title];
    [titleLabel setFrame:CGRectMake((DEVICE_WIDTH-80)/2, 5, 80, 30)];
    self.navigationItem.titleView=titleLabel;
}

-(void)showAlert
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
        
    }];
    [alert addAction:cancel];
    [alert addAction:confirm];
    [self presentViewController:alert animated:YES completion:nil];
    
}

-(void)addNoResultView
{
    _emptyView = [[IBDEmptyView alloc] initWithFrame:self.view.frame];
    [self.view addSubview:_emptyView];
    _emptyView.hidden = YES;
}

-(void)showEmptyView:(UIView *)targetView WithImage:(UIImage *)image andText:(NSString *)text subText:(NSString *)subText addEmptyRefresh:(void(^)(void))refreshingBlock
{
    targetView.hidden = YES;
    _emptyView.hidden  = NO;
    [_emptyView setImage:image andText:text andSubTex:subText];
    [_emptyView addEmptyAction:^{
        refreshingBlock();
    }];
}
-(void)hiddenEmptyView:(UIView *)targetView
{
    [_emptyView setHidden:YES];
    [targetView setHidden:NO];
}

- (void)addEmptyHeaderRefresh:(void(^)(void))refreshingBlock {
    _emptyView.mj_header =[MJRefreshNormalHeader headerWithRefreshingBlock:^{
        refreshingBlock();
    }];
    [_emptyView addEmptyAction:^{
        refreshingBlock();
    }];
    
}
-(void)emptyEndRefreshing
{
    [_emptyView.mj_header endRefreshing];
}

- (void)setNavcRightItem:(UIImage *)image andSelectorBlock:(void(^)(void))completion
{
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStyleDone target:self action:@selector(rightSelector)];
    self.navigationItem.rightBarButtonItem = rightItem;
    self.itemClick = [completion copy];
}

-(void)rightSelector
{
    self.itemClick();
}

-(void)goLogInView
{
    LogInViewController *login=[[LogInViewController alloc] init];
    UINavigationController *loginNav=[[UINavigationController alloc] initWithRootViewController:login];
    loginNav.navigationBar.barTintColor = [UIColor mainColor];
    loginNav.navigationBar.translucent  = NO;
    [self presentViewController:loginNav animated:YES completion:nil];
}


- (CGFloat)cellContentViewWith
{
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    // 适配ios7
    if ([UIApplication sharedApplication].statusBarOrientation != UIInterfaceOrientationPortrait && [[UIDevice currentDevice].systemVersion floatValue] < 8) {
    width = [UIScreen mainScreen].bounds.size.height;
    }
    return width;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
